package com.o.mj.service;

import com.o.mj.util.RedisSubscribeConfig;
import org.springframework.stereotype.Service;
import redis.clients.jedis.Jedis;
@Service
public class RedisSubscribeService {

    public static void main(String[] args) {
        Jedis jedis=new Jedis("172.16.201.222",6379);
        jedis.auth("123456");
        System.out.println(jedis.ping() + "：此时与Redis成功连接!!!");

        //订阅WeChat频道
        RedisSubscribeConfig.subscribeMessage("WeChat");
        /*
            这里肯定是先订阅频道，之后才可以向该频道发布消息，也即发布在订阅之后
            所以这里调用Thread类的sleep()方法先睡眠200ms，之后再进行发布
         */
        try {
            Thread.sleep(200);
        }catch (InterruptedException e) {
            e.printStackTrace();
        }finally {
            //
        }
        RedisSubscribeConfig.publishMessage("WeChat","Hello Redis!!!");
        RedisSubscribeConfig.publishMessage("WeChat","Java and Redis!!!");
    }

}
